package com.lyb.controller;

        import com.github.pagehelper.PageInfo;
        import com.lyb.Dto.BookDto;
        import com.lyb.common.AjaxResult;
        import com.lyb.pojo.Book;
        import com.lyb.services.impl.BookServiceImpl;
        import io.swagger.annotations.Api;
        import org.springframework.beans.factory.annotation.Autowired;
        import org.springframework.web.bind.annotation.*;

        import java.time.LocalDateTime;
        import java.util.List;

@Api(tags="Book书籍")
@RestController
@RequestMapping("/book")
public class BookC {
    @Autowired
    BookServiceImpl bookService;
    @PostMapping("/add")
    public AjaxResult addBook(@RequestBody BookDto book){
        book.setCreateTime(LocalDateTime.now());
        book.setUpdateTime(LocalDateTime.now());
        bookService.addBook(book);
        return AjaxResult.success("添加成功");
    }
    @GetMapping("/pageQuery")
    public AjaxResult queryBook(Integer pageSize,Integer pageNum){
        PageInfo<Book> res= bookService.queryBookPage(pageSize,pageNum);
        return AjaxResult.success(res);
    }
    @DeleteMapping("/del")
    public AjaxResult del(Integer id){
        bookService.del(id);
        return AjaxResult.success("删除成功");
    }
    @PostMapping("/update")
    public AjaxResult update(@RequestBody Book book){
        book.setUpdateTime(LocalDateTime.now());
        bookService.update(book);
        return AjaxResult.success("修改成功");
    }
    @GetMapping("/findByBookId")
    public AjaxResult findByBookId(Long id){
        return AjaxResult.success(bookService.findByBookId(id));
    }
}
